@echo off
:: Closing Adobe reader.
tasklist /FI "IMAGENAME eq acrord32.exe" | find /i "acrord32.exe" 
 
IF ERRORLEVEL 2 GOTO EXIST
IF ERRORLEVEL 1 GOTO NOTEXIST 
 
:EXIST
taskkill /F /IM "acrord32.exe"
set reopenvar=yes
goto FIRSTCLEANING
 
:NOTEXIST
set reopenvar=no
goto FIRSTCLEANING


:FIRSTCLEANING
IF NOT EXIST master.aux goto COMPILING
::Cleaning if last compile failed
del Presentation.aux
del Presentation.log
del Presentation.out
del Presentation.synctex.gz
del Presentation.toc
del Presentation.bbl
del Presentation.synctex.gz(busy)
del Presentation.blg
GOTO COMPILING

::ERROR
:ERRORMASTER
echo Presentation.tex not found.
goto ENDWITHPAUSE

::Compiling
:COMPILING
IF NOT EXIST Presentation.tex goto ERRORMASTER
pdflatex.exe Presentation.tex
pdflatex.exe Presentation.tex
del Presentation.aux
del Presentation.nav
del Presentation.snm
del Presentation.log
del Presentation.out
del Presentation.synctex.gz
del Presentation.toc
del Presentation.bbl
del Presentation.synctex.gz(busy)
del Presentation.blg


::Starting adobe reader again
:START
IF %reopenvar%==yes start acrord32.exe Presentation.pdf
goto END

:ENDWITHPAUSE
pause

:END